/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.ufba.lasid.v1.jitclouds.mda.datatypes;

import java.util.*;
import org.apache.commons.configuration.Configuration;

/**
 *
 * @author aliriosa
 */
public class FileBasedConfiguration implements IConfiguration{
    Configuration config = null;

    public FileBasedConfiguration(Configuration config) {
        this.config = config;
    }
    
    @Override
    public <T> void set(String name, T value) {
        config.setProperty(name, value);
    }

    @Override
    public <T> T get(String name) {
        return (T) config.getProperty(name);
    }

    @Override
    public int size() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public boolean isEmpty() {
        return config.isEmpty();
    }

    @Override
    public boolean containsKey(Object key) {
        return config.containsKey((String)key);
    }

    @Override
    public boolean containsValue(Object value) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public Object get(Object key) {
        return config.getString((String)key);
    }

    @Override
    public Object put(String key, Object value) {
        config.addProperty((String)key, value);
        return value;
    }

    @Override
    public Object remove(Object key) {
        Object value = config.getString((String)key);
        config.clearProperty((String)key);
        return value;
    }

    @Override
    public void putAll(Map<? extends String, ? extends Object> m) {
        for(String s : m.keySet()){
            put(s, m.get(s));
        }
    }

    @Override
    public void clear() {
        config.clear();
    }

    @Override
    public Set<String> keySet() {
        HashSet<String> hash = new HashSet<String>();
        Iterator<String> it = config.getKeys();
        while(it.hasNext()){
            hash.add(it.next());
        }
        
        return hash;
    }

    @Override
    public Collection<Object> values() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public Set<Entry<String, Object>> entrySet() {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
}
